package com.lucnn.diamond.spring.condition;

import com.lucnn.diamond.spring.bean.RainBown;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistry implements ImportBeanDefinitionRegistrar{
    /**
     *
     * @param importingClassMetadata
     * @param registry 可以手动注册bean到容器
     */
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
                                        BeanDefinitionRegistry registry) {
        Boolean t1 = registry.containsBeanDefinition("com.lucnn.diamond.spring.bean.Yellow");
        Boolean t2 = registry.containsBeanDefinition("com.lucnn.diamond.spring.bean.Red");
        if(t1 && t2){
            RootBeanDefinition definition = new RootBeanDefinition(RainBown.class);
            registry.registerBeanDefinition("rainBow",definition);
        }
    }
}
